package cn.jiedh.app.meiweidk.baseadapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

/**
 * @name：MXK
 * @author：达摩
 * @phone：
 * @createTime： 十月-21
 * @modifyTime： 21:09:34
 * @explain：v2.0
 */
public abstract class MyGridViewAdapter<T> extends android.widget.BaseAdapter {

    private List<T> mList;
    private Context mContext;
    private int layoutId;

    public MyGridViewAdapter(Context mContext, int layoutId, List<T> mList) {

        this.mContext = mContext;
        this.layoutId = layoutId;
        this.mList = mList;

    }

    ;

    @Override
    public int getCount() {
        if (mList!=null){
            return mList.size();
        }else {
            return 0;
        }

    }

    @Override
    public T getItem(int i) {
        return mList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final ViewHolder viewHolder = getViewHolder(i, view,
                viewGroup);
        convert(viewHolder, getItem(i), i);
        return viewHolder.getConvertView();
    }

    /**
     * 回调
     * @param helper
     * @param item
     * @param position 位置
     */
    public abstract void convert(ViewHolder helper, T item, int position);

    private ViewHolder getViewHolder(int position, View convertView,
                                     ViewGroup parent) {
        return ViewHolder.get(mContext, convertView, parent, layoutId,
                position);
    }
}
